
//添加请求根目录
// var rootDocment = "http://192.168.10.103:8081";
var rootDocment = "https://reptile.akeyn.com";

function goPost(url, data, cb) {
  wx.request({
    url: rootDocment + url,
    data: data,
    method: 'post',
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    success: function (res) {
      return typeof cb == "function" && cb(res.data)
    },
    fail: function () {
      wx.showToast({
        title: '哎呀，出错了>_<',
        icon: 'none',
        duration: 5000
      })
      return typeof cb == "function" && cb(false)
    }
  })
}

function goJsonPost(url, data, cb) {
  wx.request({
    url: rootDocment + url,
    data: data,
    method: 'post',
    header: {
      'Content-Type': 'application/json',
    },
    success: function (res) {
      return typeof cb == "function" && cb(res.data)
    },
    fail: function () {
      wx.showToast({
        title: '哎呀，出错了>_<',
        icon: 'none',
        duration: 2000
      })
      return typeof cb == "function" && cb(false)
    }
  })
}

function getDataKey() {
  return ""
}
function goGet(url, data, cb) {
  wx.request({
    url: rootDocment + url,
    data: data,
    method: 'get',
    header: { 'Content-Type': 'application/x-www-form-urlencoded' },
    success: function (res) {
      return typeof cb == "function" && cb(res.data)
    },
    fail: function () {
      return typeof cb == "function" && cb(false)
    }
  })
}

// 去前后空格  
function trim(str) {
  return str.replace(/(^\s*)|(\s*$)/g, "");
}
//保存两位数字
function saveTwoNum(num) {
  return Number(num.toString().match(/^\d+(?:\.\d{0,2})?/))
}
//openid存储
function openId() {
  return "openId"
}
//腾讯地图key
function mapKey() {
  return "33WBZ-4U7EX-NL74D-7UQMZ-4FRQE-XHFMU"
}
module.exports = {
  goJsonPost: goJsonPost,
  goPost: goPost,
  trim: trim,
  getDataKey: getDataKey,
  goGet: goGet,
  openId: openId,
  mapKey: mapKey,
  saveTwoNum: saveTwoNum
}  
